var vo={};
$(function(){
	var openWindow=window.document;
	var searchHeight=$("#divform").height();
	$("#listHRA").height($(openWindow).height()-$(openWindow).height()*0.05-searchHeight-10);
	//动态设置改变操作列宽度
	var fcol=opt.split('</a>');
	var contrlColumn=0;
	if(fcol.length>0){
		contrlColumn=(fcol.length-1)*fcolMaxWidth;
	}
	$("#listHRA").datagrid({
					url:'/hra/getdetail',
					title:'HRA数据列表',
					method:'get',
					pagination:true,
					pageList: [15,30,100,500],
					loadMsg:'加载中......',
					toolbar:'#tb',
					columns:[[
					         {field:'ck',checkbox:true},
							 {field:'did' ,align:'center',title:'操作',width:contrlColumn,formatter: function(value, row, index){
								 var re=new RegExp("{param}","g");
								 var ref=opt.replace(re,value);
								 re=new RegExp("{param2}","g");
								 ref=ref.replace(re,row.deviceid);
								 re=new RegExp("{param3}","g");
								 ref=ref.replace(re,row.idcard);
								 return ref;
							 }},
							 {field:'idcard',title:'身份证号',width:120,align:'center'},
					         {field:'username',title:'用户名称',width:80,align:'center'},
					         {field:'sex',title:'性别',width:40,align:'center'},
					         {field:'huiyuanziliao_nianling',title:'年龄',width:40,align:'center'},
					         {field:'birthdate',title:'出生日期',width:80,sortable:true,align:'center',formatter:function(value,row,index){
					        	 if(value==''){
					        		 return '';
					        	 }
					        	 var datetime=Common.formatterDate(value);
					        	 return datetime;
					         }},
					         {field:'address',title:'住址',width:250,align:'center'},
					         {field:'phone',title:'电话',width:100,align:'center'},
					         {field:'huiyuanziliao_jianchariqi',title:'检查日期',sortable:true,width:80,align:'center'},
					         {field:'huiyuanziliao_jianchashijian',title:'检查时间',width:80,align:'center'},
					         {field:'dealerid',title:'经销商编号',width:80,align:'center'},
					         {field:'dealername',title:'经销商名称',width:80,align:'center'},
					         {field:'shopid',title:'门店编号',width:80,align:'center'},
					         {field:'shopname',title:'门店名称',width:80,align:'center'},
					         {field:'deviceid',title:'设备编号',width:80,align:'center'},
					         {field:'devicename',title:'检查设备',width:80,align:'center'},
					         {field:'modelname',title:'设备型号',width:80,align:'center'},
					         {field:'shopname',title:'检查门店',width:80,align:'center'},
					         {field:'packagename',title:'套餐名称',width:80,align:'center'},
					         {field:'rtc_shengao',title:'身高',width:50,align:'center'},
					         {field:'rtc_tizhong',title:'体重',width:50,align:'center'},
					         {field:'rtc_bmi',title:'bmi指数',width:50,align:'center'},
					         {field:'rtc_gaoya',title:'高压',width:50,align:'center'},
					         {field:'rtc_diya',title:'低压',width:50,align:'center'},
					         {field:'rtc_xinlv',title:'心率',width:50,align:'center'},
					         {field:'rtc_xueyang',title:'血氧',width:50,align:'center'},
					         {field:'rtc_zhifanghanliang',title:'脂肪含量',width:80,align:'center'},
					         {field:'rtc_jichudaixie',title:'基础代谢',width:80,align:'center'}
					     ]]
				});
	$("#serbutton").click(function(){
		vo.idcard=$("#idcard").val();
		vo.username=$("#username").val();
		vo.dealerid=$("#dealerid").val();
		vo.dealername=$("#dealername").val();
		vo.shopid=$("#shopid").val();
		vo.shopname=$("#shopname").val();
		vo.deviceid=$("#deviceid").val();
		vo.devicename=$("#devicename").val();
		vo.devicemodel=$('#devicemodel').combobox('getValue');
		vo.iscount=$('#iscount').combobox('getValue')
		vo.begintime=$('#beginTime').datebox('getValue');
		vo.endtime=$('#endTime').datebox('getValue');
		$("#listHRA").datagrid('load',vo);
	});
	$("#devicemodel").combobox({
		 url:'/model/getCombobox',
		 valueField:'id',
		 textField:'text',
	});
	var isc=[{'id':'1','text':'是'},{'id':'0','text':'否'}];
	$("#iscount").combobox({
		 data:isc,
		 valueField:'id',
		 textField:'text',
	});
	//绑定回车事件
	$(document).keydown(function(event){ 
		if(event.keyCode==13){
			$("#serbutton").click(); 
		}
	});
	$('#listHRA').datagrid({   
	    rowStyler:function(index,row){
	        if (!row.iscount){   
	            return 'background-color:'+window.notCountColor;   
	        }
	    }  
	});
	$('#beginTime').datebox({});  
	$('#endTime').datebox({}); 
	//如果操作项为空隐藏操作列
	if(opt==''){
		$("#listHRA").datagrid('hideColumn','did');
	}
});
/**
 * 打开view页
 */
function viewHRA(id){
	window.parent.opentab('01001','HRA数据详情','/hra/view','id='+id);
}
/**
 * 作废
 */
function cancleCount(){
	var rows=$("#listHRA").datagrid('getSelections');
	if(rows.length<=0){
		$.messager.alert('错误','选中的记录为空','error');
		return;
	}
	$.messager.confirm('作废','您确定要作废选中的体检数据吗？',function(data){
		if(data){
			var ids='';
			for(var i=0;i<rows.length;i++){
				ids+=rows[i].did+',';
			}
			$.ajax({
				type:'get',
				url: '/hra/concleCount',
				data:{ids:ids},
				success:function(data){
					if(data.code==200){
						$.messager.alert("作废","作废成功",'info',function(){
							$("#listHRA").datagrid('load',vo);
						});
					}
					else{
						$.messager.alert("失败","作废失败："+data.msg,'error');
					}
				},
				error:function(data){
					$.messager.alert("失败","作废失败：",'error');
				}
			});
		}
	})
}
/**
 * 取消作废
 */
function Count(){
	var rows=$("#listHRA").datagrid('getSelections');
	if(rows.length<=0){
		$.messager.alert('错误','选中的记录为空','error');
		return;
	}
	$.messager.confirm('作废','您确定要取消作废选中的体检数据吗？',function(data){
		if(data){
			var ids='';
			for(var i=0;i<rows.length;i++){
				ids+=rows[i].did+',';
			}
			$.ajax({
				type:'get',
				url: '/hra/Count',
				data:{ids:ids},
				success:function(data){
					if(data.code==200){
						$.messager.alert("作废","启用成功",'info',function(){
							$("#listHRA").datagrid('load',vo);
						});
					}
					else{
						$.messager.alert("失败","启用失败："+data.msg,'error');
					}
				},
				error:function(data){
					$.messager.alert("失败","启用失败：",'error');
				}
			});
		}
	})
}
/**
 * 导出为excel
 */
function exportXls(){
	vo.dealerid=getVal(vo.dealerid);
	vo.idcard=getVal(vo.idcard);
	vo.username=getVal(vo.username);
	vo.dealername=getVal(vo.dealername);
	vo.shopid=getVal(vo.shopid);
	vo.shopname=getVal(vo.shopname);
	vo.deviceid=getVal(vo.deviceid);
	vo.devicename=getVal(vo.devicename);
	vo.devicemodel=getVal(vo.devicemodel);
	vo.iscount=getVal(vo.iscount);
	vo.begintime=getVal(vo.begintime);
	vo.endtime=getVal(vo.endtime);
	var url='/hra/exportXls?dealerid='+vo.dealerid+'&idcard='+vo.idcard+'&username='+
	vo.username+'&dealername='+vo.dealername+'&shopid='+vo.shopid+'&shopname='+vo.shopname+
	'&deviceid='+vo.deviceid+'&devicename='+vo.devicename+'&devicemodel='+vo.devicemodel+'&iscount='+vo.iscount+
	'&begintime='+vo.begintime+'&endtime='+vo.endtime;
	window.open(url,'','',false);
}
